package org.fujay.commons.langchain4j.param;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import dev.langchain4j.data.message.ChatMessageType;
import dev.langchain4j.model.output.TokenUsage;
import lombok.*;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Message implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    private String userId;

    private Object memoryId;

    private ChatMessageType role;

    private String content;

    private Boolean error;

    private TokenUsage tokenUsage;

    private String createAt;

    public static Message error(String id, Object chatId, String content) {
        return Message.builder()
                .userId(id)
                .memoryId(chatId)
                .role(ChatMessageType.AI)
                .createAt(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN))
                .content(content)
                .error(true)
                .build();
    }

    public static Message complete(String id, Object chatId, String content, TokenUsage tokenUsage) {
        return Message.builder()
                .userId(id)
                .memoryId(chatId)
                .role(ChatMessageType.AI)
                .createAt(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN))
                .content(content)
                .tokenUsage(tokenUsage)
                .build();
    }

    public static Message next(String id, Object chatId, String content) {
        return Message.builder()
                .userId(id)
                .memoryId(chatId)
                .role(ChatMessageType.AI)
                .createAt(LocalDateTimeUtil.format(LocalDateTime.now(), DatePattern.NORM_DATETIME_PATTERN))
                .content(content)
                .build();
    }


}
